package com.jiazixuan.stock.controller;

import com.jiazixuan.stock.pojo.domain.SysUserDomain;
import com.jiazixuan.stock.pojo.entity.SysUser;
import com.jiazixuan.stock.service.UserService;
import com.jiazixuan.stock.vo.req.AddUserReqVo;
import com.jiazixuan.stock.vo.req.LoginReqUsers;
import com.jiazixuan.stock.vo.req.LoginReqVo;
import com.jiazixuan.stock.vo.req.SysUserUpdateReqVo;
import com.jiazixuan.stock.vo.resp.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api("/api")
@RestController
@RequestMapping("/api")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "string", name = "userName", value = "", required = true)
    })
    @ApiOperation(value = "根据用户名获取用户信息", notes = "", httpMethod = "GET")
    @GetMapping("/user/{userName}")
    public SysUser getUserByUserName(@PathVariable("userName") String name){
        return userService.findByUserName(name);
    }


//    @ApiOperation(value = "用户登录功能")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "vo",value = "用户请求请求登录数据",paramType = "LoginReqVo",required = true,type = "body")
//    })
//    @PostMapping("/login")
//    public R<LoginRespVo> login(@RequestBody LoginReqVo vo){
//        return userService.login(vo);
//    }
//    @ApiImplicitParams({
//            @ApiImplicitParam(paramType = "body", dataType = "LoginReqVo", name = "vo", value = "", required = true)
//    })
//    @ApiOperation(value = "用户登录功能", notes = "}", httpMethod = "POST")
//
//    @PostMapping("/login")
//    public R<LoginRespVoWithMenusAndPermissions> login(@RequestBody LoginReqVo vo){
//        return userService.login(vo);
//    }

    /**
     * 生成登录校验码的访问接口
     * @return
     */
    @ApiOperation(value = "验证码生成", notes = "生成登录校验码的访问接口", httpMethod = "GET")
    @GetMapping("/captcha")
    public R<Map> getCaptchaCode(){
        return userService.getCaptchaCode();
    }

    /**
     *多条件综合查询用户分页信息
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "LoginReqUsers", name = "users", value = "", required = true)
    })
    @ApiOperation(value = "多条件综合查询用户分页信息", notes = "多条件综合查询用户分页信息", httpMethod = "POST")
    @PostMapping("/users")
    public R<PageResult<SysUserDomain>> getUsers(@RequestBody LoginReqUsers users){
        return userService.getUsers(users);
    }

    /**
     * 添加用户
     */
    @PostMapping("/user")
    public R addUser(@RequestBody AddUserReqVo vo){
        return userService.addUser(vo);
    }

    /**
     * 删除用户
     */
    @DeleteMapping("/user")
    public R deleteUser(@RequestBody List<Long> userIds){
        return userService.deleteUser(userIds);
    }

    /**
     * 根据用户id查询用户信息
     */
    @GetMapping("/user/info/{userId}")
    public R<UserInfoRespVo> getUserInfoById(@PathVariable(value = "userId") String id){
        return userService.getUserInfoById(id);
    }

    /**
     * 根据id更新用户基本信息
     */
    @PutMapping("/user")
    public R updateUserInfoById(@RequestBody SysUserUpdateReqVo vo){
        return userService.updateUserInfoById(vo);
    }
}
